package com.sc.nft.dto;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.entity.vo.AdminSimpleCastCollectionVO;
import com.sc.nft.entity.vo.ecology.EcologyCastListVO;
import com.sc.nft.entity.vo.ecology.AdminGetPageCastConfVO;
import com.sc.nft.entity.vo.ecology.EcologyCastDetailsVO;
import lombok.extern.slf4j.Slf4j;
import com.sc.nft.entity.EcologyCastConf;
import com.sc.nft.mapper.EcologyCastConfMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 生态-铸造-配置(sc_ecology_cast_conf)数据DAO
 *
 * @author Sun
 * @since 2023-10-13 17:22:11
 * @description 由 Mybatisplus Code Generator 创建
 */
@Slf4j
@Repository
public class EcologyCastConfDao extends ServiceImpl<EcologyCastConfMapper, EcologyCastConf> {

    public boolean updateSortById(Long id, Long sort) {
        LambdaUpdateWrapper<EcologyCastConf> wrapper = new LambdaUpdateWrapper<>();
        wrapper.set(EcologyCastConf::getSort, sort);
        wrapper.eq(EcologyCastConf::getId, id);
        return update(new EcologyCastConf(),wrapper);
    }

    public Page<AdminGetPageCastConfVO> getPageCastConf(String collectionName, Integer pageNo, Integer pageSize) {
        return baseMapper.getPageCastConf(new Page<>(pageNo, pageSize), collectionName);
    }

    public boolean updateStatusById(Long id, Boolean status) {
        LambdaUpdateWrapper<EcologyCastConf> wrapper = new LambdaUpdateWrapper<>();
        wrapper.set(EcologyCastConf::getStatus, status);
        wrapper.eq(EcologyCastConf::getId, id);
        return update(new EcologyCastConf(),wrapper);
    }

    public boolean delCastConfById(Long id) {
        return this.lambdaUpdate()
                .eq(EcologyCastConf::getId, id)
                .remove();
    }

    public Page<EcologyCastListVO> getPageEcologyCast(Integer pageNo, Integer pageSize,Long userCreatorId) {
        return baseMapper.getPageEcologyCast(new Page<>(pageNo, pageSize),userCreatorId);
    }

    public EcologyCastDetailsVO getProductDetailsById(Long ecologyCastConfId) {
        return baseMapper.getProductDetailsById(ecologyCastConfId);
    }

    public EcologyCastConf getOneByCollectionId(Long collectionId) {
        LambdaQueryWrapper<EcologyCastConf> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(EcologyCastConf::getCollectionId, collectionId);
        wrapper.eq(EcologyCastConf::getStatus, Boolean.TRUE);
        wrapper.orderByDesc(EcologyCastConf::getId);
        wrapper.last("limit 1");
        return getOne(wrapper);
    }

    public List<EcologyCastConf> getOneByCollectionId(List<Long> collectionIds) {
        LambdaQueryWrapper<EcologyCastConf> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(EcologyCastConf::getCollectionId, collectionIds);
        wrapper.eq(EcologyCastConf::getStatus, Boolean.TRUE);
        wrapper.orderByDesc(EcologyCastConf::getId);
        wrapper.last("limit 1");
        return list(wrapper);
    }

    public Page<AdminSimpleCastCollectionVO> getSimplePage(Integer pageNo, Integer pageSize) {
        return baseMapper.getSimplePage(new Page<>(pageNo, pageSize));
    }

    public List<EcologyCastConf> getAll() {
        return baseMapper.getAll();
    }
}